﻿using System.Windows;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;
using LiSAClient.Core.Interfaces;
using LiSAClient.Core.Services;
using LiSAClient.Core.Services.Factories;
using LiSAClient.Core.Viewmodel;
using LiSAClient.LiSAService;

namespace LiSAClient.WpfClient.ViewModel.Projects.Edit
{
    class EditSearchstringsViewModel  : ContentViewModel, ICommitable
    {
        #region Observables
        public ICommand Commit { get; private set; }

        private Project project;
        public Project Project
        {
            get
            {
                return this.project;
            }

            set
            {
                this.Set(() => this.Project, ref this.project, value);
            }
        }
        #endregion
        #region Initializers
        public EditSearchstringsViewModel(Project proj)
        {
            this.Project = proj;
            this.Commit = new RelayCommand(UpdateProject);
        }
        #endregion
        public override void OnPresented()
        {

        }
        #region Methods
        /// <summary>
        /// Update the Project
        /// </summary>
        public void UpdateProject()
        {
            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Update Project?", "Update Confirmation", System.Windows.MessageBoxButton.YesNo);
            if (messageBoxResult == MessageBoxResult.Yes)
            {
                ServiceFactory.Instance.Get<ProjectService>().UpdateProject(this.Project);

                // Close the window
                if (this.Presenter != null)
                {
                    this.Presenter.SendClosingRequest();
                }
            }
        }
        #endregion
    }
}